package com.sugar.real.estate.module.business.dal.mysql.designplan;

import cn.hutool.core.util.StrUtil;
import com.sugar.real.estate.framework.common.pojo.PageParam;
import com.sugar.real.estate.framework.common.pojo.PageResult;
import com.sugar.real.estate.framework.mybatis.core.mapper.BaseMapperX;
import com.sugar.real.estate.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.sugar.real.estate.module.business.controller.admin.designplan.vo.DesignPlanPageReqVO;
import com.sugar.real.estate.module.business.dal.dataobject.designplan.DesignPlanDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 设计方案 Mapper
 *
 * @author Ysugar
 */
@Mapper
public interface DesignPlanMapper extends BaseMapperX<DesignPlanDO> {

    default PageResult<DesignPlanDO> selectPage(DesignPlanPageReqVO reqVO) {
        String title = reqVO.getTitleZhCn();
        return selectPage(reqVO, new LambdaQueryWrapperX<DesignPlanDO>()
                .eqIfPresent(DesignPlanDO::getTitleZhCn, reqVO.getTitleZhCn())
                .eqIfPresent(DesignPlanDO::getTitleEnUs, reqVO.getTitleEnUs())
                .betweenIfPresent(DesignPlanDO::getCreateTime, reqVO.getCreateTime())
                .nested(StrUtil.isNotBlank(title), o -> o.like(DesignPlanDO::getTitleZhCn, title)
                        .or().like(DesignPlanDO::getTitleEnUs, title))
                .orderByDesc(DesignPlanDO::getId));
    }

    default PageResult<DesignPlanDO> appSelectPage(PageParam reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DesignPlanDO>().orderByDesc(DesignPlanDO::getId));
    }

}